package com.msmall.community.admin.action;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.community.admin.model.AdminUser;
import com.msmall.community.admin.service.AdminSecurityManager;
import com.msmall.community.common.OnlineUser;

public class LoginAction extends HTMLBaseAction{

	private static final long serialVersionUID = 8499579923825871471L;
	
	private String adminUsername;
	
	private String adminPassword;
	
	private AdminSecurityManager adminSecurityManager;
	
	public String execute(){
		try{
			if(adminSecurityManager.authenticate(adminUsername, adminPassword)){
				AdminUser admin = adminSecurityManager.getByUsername(adminUsername);
				OnlineUser.adminAuthenticated(getUserid(), admin.getUserId(), getSession());
				return SUCCESS;
			}else{
				return ERROR;
			}
		}catch(Exception e){
			return ERROR;
		}
	}

	public String getAdminUsername() {
		return adminUsername;
	}

	public void setAdminUsername(String adminUsername) {
		this.adminUsername = adminUsername;
	}

	public String getAdminPassword() {
		return adminPassword;
	}

	public void setAdminPassword(String adminPassword) {
		this.adminPassword = adminPassword;
	}

	public void setAdminSecurityManager(AdminSecurityManager adminSecurityManager) {
		this.adminSecurityManager = adminSecurityManager;
	}
}
